<script type="text/javascript">
// popup change handlers go here
function moduleOrderIsKosher()
{
	// module1 and module2
	// module3 and module4
	// module6, module7, module8, module9
	
	var val1 = document.getElementById('module1').value;
	var val2 = document.getElementById('module2').value;
	
	var val3 = document.getElementById('module3').value;
	var val4 = document.getElementById('module4').value;
	
	var val6 = document.getElementById('module6').value;
	var val7 = document.getElementById('module7').value;
	var val8 = document.getElementById('module8').value;
	var val9 = document.getElementById('module9').value;
	
	if(val1 == val2) return false;
	if(val3 == val4) return false;
	if(val6 == val7 || val6 == val8 || val6 == val9 ||
		               val7 == val8 || val7 == val9 || 
		                               val8 == val9) return false;
	return true;
}

</script>

<?php
 
	$funeralhome_id = $this->VAS_fh_id;
	$modules = explode("|", $this->modules );
	$action = $this->url(array('controller'=>'index',
			'action'=>'funeraldirectormodules'));

	$popupContents = array();
	$popupContents["NONE"] = "None";
	$popupContents["MERCHANDISE"] = "Merchandise";
	$popupContents["CATERING"] = "Catering";
	$popupContents["FLORAL"] = "Floral";
	$popupContents["CASHADV"] = "Cash Advances";

	function makeModulePopup( $popupContents, $selected, $id )
	{
		$html = "<select size=1 id=\"$id\" name=\"module_order[]\">\n";
		foreach( $popupContents as $key=>$value )
		{
			$html .= "<option value=\"$key\"";
			if($key == $selected)
			{
				$html .= " selected>$value</option>";
			}
			else
			{
				$html .= ">$value</option>";
			}
		}
		$html .= "</select>\n";
		return $html;
	}

// first two popups specify order of substeps in Burial and Cremation sequence

// it's already unpacked in $modules, so we can look for "BURIAL" and take the key beyond it
// and do the same with "CREMATION".  we can then paste them together to make the value for
// the popup

//	Burial: "BURIAL|CASKET" / "CASKET|BURIAL"

	$burialOptions = array( "BURIAL"=>"Burial Tributes", "CASKET"=>"Casket Showroom" );
	
	$b1Value = $modules[4];
	$b2Value = $modules[5];
		
//	Cremation: "CREMATION|URN" / "URN|CREMATION"
	
	$cremationOptions = array( "CREMATION"=>"Cremation Tributes", "URN"=>"Urn Showroom" );
	
	$c1Value = $modules[6];
	$c2Value = $modules[7];
	
// last four popups specify which module goes in which slot between the step summary and the
// full summary

	$mValues["MERCHANDISE"] = "Merchandise";
	$mValues["FLORAL"] = "Floral";
	$mValues["CATERING"] = "Catering";
	$mValues["CASHADV"] = "Cash Advances";	
	
// popups are built now.  render the form.

// 
	$modNum = 1;
	$ol = "<ol class=\"modulesList\">\n";
	while( false != ($element = each($modules) ))
	{
		$module_key = $element['value'];
		$module = VASProcessModules::$_modules[$module_key];		
		if(in_array( $module_key, array("INTRO", "EXPECT", "LIFE", "CHOICES" )))
		{
			$ol .= "<li>";
			$ol .= "<input type=hidden id=\"$module_key\" name=\"module_order[]\" 
				value=\"$module_key\">$module[0]";
			$ol .= "</li>";
		}
		else
		if(in_array( $module_key, array( "BURIAL", "CASKET" )))
		{
			$ol .= "<li>";
			$ol .= "If Bereaved Chooses Burial: ";
			$ol .= makeModulePopup( $burialOptions, $b1Value, "module$modNum" );

			$modNum++;
			
			$ol .= " then ";

			$ol .= makeModulePopup( $burialOptions, $b2Value, "module$modNum" );
			$ol .= "</li>";
			
			$modNum++;
			
			$element = each($modules);
			continue;
		}
		else
		if(in_array( $module_key, array( "CREMATION", "URN" )))
		{
			$ol .= "<li>";
			$ol .= "If Bereaved Chooses Cremation: ";
			$ol .= makeModulePopup( $cremationOptions, $c1Value, "module$modNum" );

			$modNum++;
			
			$ol .= " then ";

			$ol .= makeModulePopup( $cremationOptions, $c2Value, "module$modNum" );
			$ol .= "</li>";
			
			$modNum++;
			
			$element = each($modules);
			continue;
		}
		else
		if(in_array( $module_key, array("MERCHANDISE", "FLORAL", "CATERING", "CASHADV" )))
		{
			$modNum++;
			
			$ol .= "<li>";
			$ol .= makeModulePopup( $popupContents, $module_key, "module$modNum" );
			$ol .= "</li>";
		}
		else
		{			
			$ol .= "<li>";
			$ol .= "<input type=hidden id=\"$module_key\" name=\"module_order[]\" 
				value=\"$module_key\">$module[0]";
			$ol .= "</li>";
		}		
	}
	$ol .= "</ol>\n";
	$FDMS_license_number = $this->FDMS_license_number;
 ?>

<ul class="basictab">
<li><a href="/index/funeraldirector/funeraldir_id/<?php echo $FDMS_license_number?>">Profile</a></li>
<li class="selected"><a href="/index/funeraldirectormodules/funeraldir_id/<?php echo $FDMS_license_number?>">Module Order</a></li>
</ul>

<div class="basictabdiv">
<form method="post" action="<?php echo $action?>"  onSubmit='if(!moduleOrderIsKosher()) {alert("Some of your modules are set to repeat");return false;}'>
<?php echo $ol;?>
<br>
<input type="submit">
</form>
</div>
